/**
 * Created by Administrator on 2017/6/22 0022.
 */
import {
    instance
} from '../../../src/Wap'
// 系统全局性变量
window.Wap = instance

$(function () {
    // 右滑动时返回
    Wap.SwipeRightBack('fplan.html');

    // 事件关联
    $('#pid_setter_btn').click(function () {
        Wap.ApiRequest('fevent/picker',null,function (rdata) {
            if(rdata.code != 1){
                weui.topTips(rdata.msg);
                return;
            }
            weui.picker(rdata.data, {
                onConfirm: function (result) {
                    console.log(result)
                    $('#pid_ipter').val(result[0].value);
                    $('#pref_pid_ipter').val(result[0].label);
                },
                id: 'finance_plan_picker'
            });
        });
    });

    // 表单提交
    weui.form.checkIfBlur('.js__form');
    $('#submit_lnk').click(function () {
        weui.form.validate('.js__form', function (error) {
            if(!error){
                Wap.ApiRequest('fplan/save',Wap.formJson('.js__form'),function (data) {
                    if(data.code == -1){
                        weui.alert(data.msg);
                        return null;
                    }
                    Wap.msg_success(data.msg,'财务计划');
                });
            }
        });
    });
});